"""add_workflow_share

Revision ID: 46165883543c
Revises: 06e3119ca303
Create Date: 2025-05-14 12:40:04.314586

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '46165883543c'
down_revision: Union[str, None] = '06e3119ca303'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    op.create_table(
        'workflow_shares',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('workflow_id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.Column('is_public', sa.Boolean(), nullable=False, default=False),
        sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now()),
        sa.PrimaryKeyConstraint('id'),
        sa.ForeignKeyConstraint(['workflow_id'], ['workflows.id'], ondelete='CASCADE'),
        sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
    )
    op.create_index(op.f('ix_workflow_shares_id'), 'workflow_shares', ['id'], unique=False)
    op.create_index(op.f('ix_workflow_shares_workflow_id'), 'workflow_shares', ['workflow_id'], unique=False)
    op.create_index(op.f('ix_workflow_shares_user_id'), 'workflow_shares', ['user_id'], unique=False)


def downgrade() -> None:
    """Downgrade schema."""
    op.drop_index(op.f('ix_workflow_shares_user_id'), table_name='workflow_shares')
    op.drop_index(op.f('ix_workflow_shares_workflow_id'), table_name='workflow_shares')
    op.drop_index(op.f('ix_workflow_shares_id'), table_name='workflow_shares')
    op.drop_table('workflow_shares')
